<?php

namespace app\admin\controller;

use app\admin\AdminBaseController;
use app\common\model\SettingModel;

class Setting extends AdminBaseController
{
    /**
     * 短信配置
     */
    public function sms()
    {
        $sms = SettingModel::getConfigValue(SettingModel::SMS);
        return view('', [
            'sms' => $sms,
            'sms_type' => SettingModel::SMS_TYPE,
        ]);
    }

    public function editSms()
    {
        $data = $this->_post(SettingModel::SMS);
        SettingModel::setConfigValue($data);
        ajax_return();
    }

    /**
     * 系统配置
     */
    public function system()
    {
        $system = SettingModel::getConfigValue(SettingModel::SYSTEM);
        return view('', [
            'system' => $system,
        ]);
    }

    public function editSystem()
    {
        $data = $this->_post(SettingModel::SYSTEM);
        SettingModel::setConfigValue($data);
        ajax_return();
    }

    /**
     * 获取数据
     * @param array $param 要获取的数据
     * @return array
     */
    public function _post(array $param)
    {
        $res = [];
        foreach ($param as $v) {
            if (!empty(input($v))) {
                $res[$v] = input($v);
            }
        }

        return $res;
    }
}